package cn.lyvust.first.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import cn.lyvust.first.common.bean.ResponseCode;
import cn.lyvust.first.common.bean.ResponseResult;
import cn.lyvust.first.common.exception.RequestException;
import cn.lyvust.first.manage.dto.param.ExpertLogbookParam;
import cn.lyvust.first.manage.entity.ExpertLogbook;
import cn.lyvust.first.manage.service.ExpertLogbookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * @author ggzheng
 * @since 2021-01-19
 */
@Api(tags = {"专家活动"})
@RestController
@RequestMapping("/evaluation/expert_logbook")
public class ExpertLogbookController {

    @Autowired
    private ExpertLogbookService expertLogbookService;

    @PostMapping(value = {"/list/userid"})
    @ApiOperation(value = "获取指定用户的所有活动")
    public ResponseResult listByUserId(@RequestBody ExpertLogbookParam param){
        if (StringUtils.isEmpty(param.getUserId())) {
            throw RequestException.fail("特派员的ID不能为空!");
        }
        QueryWrapper<ExpertLogbook> wrapper = new QueryWrapper<>();
        wrapper.eq("expert_id", param.getUserId()).orderByDesc("in_date");
        IPage res = expertLogbookService.page(
                new Page<ExpertLogbook>(param.getPage(), param.getPageSize()), wrapper);
        return ResponseResult.e(ResponseCode.OK, res);
    }
}
